import Vue from "vue";
import VueRouter from "vue-router";
import Index from "../views/index.vue";
import Zhinan from "../views/zhinan.vue";
import Zhidu from "../views/zhidu.vue";
import Guanyu from "../views/guanyu.vue";
import Tese from "../views/tesecontent.vue";
import Login from "../views/login.vue";
import Chaxun from "../views/chaxun.vue";
import hootBox from "../views/hootBox.vue";
import News1 from "../views/news1.vue";

Vue.use(VueRouter);

const routes = [
  { path: "/", redirect: "/index" },
  { path: "/index", component: Index },
  { path: "/zhinan", component: Zhinan },
  { path: "/zhidu", component: Zhidu },
  { path: "/guanyu", component: Guanyu },
  { path: "/tese/:id", component: Tese, props: true },
  { path: "/login", component: Login },
  { path: "/chaxun", component: Chaxun ,
    beforeEnter: (to, from, next) => {
      if(sessionStorage.getItem('token')){
        next()
      }else{
        alert('您无此权限，请登录后重新尝试')
      }
    }
 },
  { path: "/hootBox", component: hootBox ,
  beforeEnter: (to, from, next) => {
    if(sessionStorage.getItem('token')){
      next()
    }else{
      alert('您无此权限，请登录后重新尝试')
    }
  }
},
  {path:'/news1',component:News1}
];

const router = new VueRouter({
  routes,
});

export default router;
